package com.droowa.model.dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.type.Alias;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.droowa.domain.OrderInfo;
import com.droowa.domain.OrderList;
import com.droowa.domain.OrderProduct;

@Repository
public class OrderDAOMybatisImpl implements OrderDAO{
	
	@Autowired
	private SqlSessionTemplate session;
	

//####################### OrderInfo Service ########################
	@Override
	public int insertOrderInfo(OrderInfo orderInfo) throws SQLException {
		return session.insert("order.insertOrderInfo", orderInfo);	
	}

	
//####################### OrderProduct Service ########################
	@Override
	public int insertOrderProduct(OrderProduct orderProduct)throws SQLException {
		return session.insert("order.insertOrderProduct", orderProduct);
	}


	@Override
	public OrderProduct getOrderProductById(String orderProductId) throws SQLException {
		return session.selectOne("order.getOrderProductById", orderProductId);
	}
	
	public List<OrderProduct> getOrderListById(String custId) throws SQLException {
		return session.selectList("order.getOrderListById", custId);
	}


	@Override
	public int updateOrderProductResult(String completeId) throws SQLException {
		return session.update("order.updateOrderProductResult", completeId);
	}
	
	@Override
	public int updateOrderProductResultFalse(String completeId) throws SQLException {
		return session.update("order.updateOrderProductResultFalse", completeId);
	}
	@Override
	public int deleteOrderProduct(String custId, String completeId) throws SQLException{
		HashMap<String, String> map=new HashMap<String, String>();
		map.put("custId", custId);
		map.put("completeId", completeId);
		return session.delete("order.deleteOrderProduct", map);
	}
	
	@Override
	public int insertOrderList(OrderList orderList) throws SQLException{
		return session.insert("order.insertOrderList", orderList);
	}

	//####################### 주문 내역  ########################
	@Override
	public List<OrderList> getOrderListByCustId(String custId) throws SQLException {
		System.out.println("주문내역");
		return session.selectList("order.getOrderListByCustId", custId);
	}
	
	
}
